// top search

function doSearch(e)
{
	if (e)
	{
		var keyCode = e.keyCode || e.which;
		if (keyCode != 13)
			return;
			
		e.returnValue = false;
		e.cancelBubble = true;
		if (e.preventDefault)
		{
			e.stopPropagation();
			e.preventDefault();
		}
	}
	
	var searchBox = document.getElementById("searchBox");
	var url = "http://search.telerik.com/search?q=" + searchBox.value +"&filter=0&btnG.x=18&sort=date%3AD%3AL%3Ad1&output=xml_no_dtd&btnG.y=12&oe=UTF-8&ie=UTF-8&client=telerik&proxystylesheet=telerik&btnG.x=14&btnG.y=20";
	if (searchBox.value != "" && searchBox.value != "Search")
	{
		window.open(url, "_blank");
	}
}

function clearSearch()
{
	var searchBox = document.getElementById("searchBox");
	if (searchBox.value == "Search")
	{
		searchBox.value = "";
	}
}


// expand, collapse examples

function toggleDisplay(blockId, titleId)
{
	var block = document.getElementById(blockId);
	var title = document.getElementById(titleId);
	if (block.className.indexOf("qsfNone") == -1)
	{
		block.className = block.className + " qsfNone";
		title.className = "qsfSubtitleCollapsed";
	}
	else
	{
		block.className = block.className.replace(/qsfNone/, "");
		title.className = "qsfSubtitle";
	}
	return false;
}


// code viewer new window opener

function showCodeInExternalWindow()
{
	var codeViewerContents = document.getElementById("codeContent");
	var wnd = window.open("", "codeViewer", "status=0,toolbar=0,scrollbars=1");
	wnd.document.open();
	wnd.document.write("<html><head>");
	wnd.document.write("<title>");
	wnd.document.write(document.title);
	wnd.document.write("</title></head><body>");
	wnd.document.write(codeViewerContents.innerHTML);
	wnd.document.write("</body></html>");
	wnd.document.close();
}

// demo thumbnails slider

function InitDemoSlider(sender, eventArgs)
{
	var sliderId = sender.get_id();
	eval("initialValue_" + sliderId + " = sender.get_minimumValue();");
	
	HandleClientValueChange(sender, null);
}

function HandleClientValueChange(sender, eventArgs)
{
	var sliderId = sender.get_id();
	
	var wrapper = document.getElementById(sliderId + "_wrapper");
	var content = document.getElementById(sliderId + "_content");

	var oldValue = (eventArgs) ? eventArgs.get_oldValue() : sender.get_minimumValue();
	var change = sender.get_value() - oldValue;

	var contentWidth = content.scrollWidth - wrapper.offsetWidth;
	var calculatedChangeStep = contentWidth / ((sender.get_maximumValue() - sender.get_minimumValue()) / sender.get_slideStep());

	eval("initialValue_" + sliderId + " = initialValue_" + sliderId + " - change * calculatedChangeStep;");

	eval("content.style.left = initialValue_" + sliderId + " + 'px';");
	
	if (sender.get_value() == sender.get_minimumValue())
	{
		eval("content.style.left = 0;");
	}
}